package com.weipt.juc.volatile1;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author peter.wei 2020/09/27 10:27
 * @version 1.0
 * @company CBI
 * @description <br>peter.wei 2020/09/27 10:27
 **/
public class VTest02_atomic {

    //public static int NUM = 0;   此处不加volatile,NUM=1这个操作针对于TheadA是不可见的
    public static AtomicInteger NUM = new AtomicInteger();

    public static void main(String[] args) throws InterruptedException {

        new Thread(()-> {
            while (NUM.equals(0)){
               // System.out.println("start");
            }
        }, "TheadA").start();

        TimeUnit.SECONDS.sleep(1);

        NUM.addAndGet(1);
        System.out.println(NUM);

        //new Thread(()->NUM = 1).start();
    }
}